package com.lxl.servlet;

import com.lxl.core.TaskExecutor;
import com.lxl.message.MsgStatus;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public abstract class BaseLongServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TaskExecutor task = getTask(request, response);
        task.start();

        response.getWriter().write(task.getTaskDataMeta().msgProvider.provideMessage(MsgStatus.LONG_TASK_RUN,
                task.getTaskDataMeta().taskLocalConfigFileName + " start now."));
        response.getWriter().flush();
    }

    abstract protected TaskExecutor getTask(HttpServletRequest request, HttpServletResponse response);
}
